<template>
  <!-- 院系调整弹窗 -->
  <el-dialog
    width="50%"
    title="分配班级"
    :visible.sync="openDlg"
    append-to-body="true"
    destroy-on-close
  >
    <!-- 添加或修改角色配置对话框 -->
    <el-form ref="form" :model="form" :rules="rules" label-width="95px">
      <el-row>
        <el-col :span="8">
          <el-form-item label="所属院系" prop="deptId">
            <el-cascader clearable
            v-model="form.deptId"
            :options="deptOptions"
            :props="{ value: 'id',currentLabels: 'label',checkStrictly: true}"
            @change="handleChange"
            style="width: 100%;"
          ></el-cascader>
            <!-- <el-select
              v-model="form.deptId"
              placeholder="请选择"
              clearable
              class="elSelect"
              @change="handleChange"
              style="width: 100%"
            >
              <el-option
                v-for="item in deptOptions"
                :key="item.id"
                :label="item.label"
                :value="item.id"
              ></el-option> -->
            <!-- </el-select> -->
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="来校日期" prop="admissionTime">
            <el-date-picker
              clearable
              v-model="form.admissionTime"
              type="date"
              value-format="yyyy-MM-dd"
              placeholder="选择来校日期"
              style="width: 100%"
            ></el-date-picker>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="工号" prop="tno">
            <el-input
              v-model.trim="form.tno"
              clearable
              placeholder="请输入工号"
              maxlength="30"
              disabled
            />
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="姓名" prop="name">
            <el-input
              v-model.trim="form.name"
              clearable
              placeholder="请输入姓名"
              maxlength="10"
              disabled
            />
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="性别" prop="sex">
            <el-select
              v-model="form.sex"
              clearable
              placeholder="请选择性别"
              style="width: 100%"
            >
              <el-option
                v-for="dict in dict.type.sys_user_sex"
                :key="dict.value"
                :label="dict.label"
                :value="dict.value"
              ></el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="在职状态" prop="postStatus">
            <el-select
              v-model="form.postStatus"
              clearable
              placeholder="请选择在职状态"
              style="width: 100%"
            >
              <el-option
                v-for="dict in dict.type.basic_post_status"
                :key="dict.value"
                :label="dict.label"
                :value="dict.value"
              ></el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="血型" prop="bloodType">
            <el-select
              clearable
              v-model="form.bloodType"
              placeholder="请选择血型"
              style="width: 100%"
            >
              <el-option
                v-for="dict in dict.type.basic_blood_type"
                :key="dict.value"
                :label="dict.label"
                :value="dict.value"
              ></el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="身份证件号" prop="cardCode">
            <el-input
              v-model.trim="form.cardCode"
              placeholder="请输入身份证件号"
              clearable
              maxlength="18"
              @blur="codeBulr"
            />
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="出生日期" prop="birthday">
            <el-date-picker
              clearable
              v-model="form.birthday"
              disabled
              type="date"
              placeholder="选择出生日期"
              style="width: 100%"
              value-format="yyyy-MM-dd"
              format="yyyy-MM-dd"
            ></el-date-picker>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="联系方式" prop="phone">
            <el-input
              v-model.trim="form.phone"
              clearable
              placeholder="请输入联系方式"
              maxlength="11"
            />
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="民族" prop="nation">
            <el-select
              v-model="form.nation"
              clearable
              placeholder="请选择民族"
              style="width: 100%"
            >
              <el-option
                v-for="dict in dict.type.bc_nation_type"
                :key="dict.value"
                :label="dict.label"
                :value="dict.value"
              ></el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="政治面貌" prop="political">
            <el-select
              v-model="form.political"
              clearable
              placeholder="请选择政治面貌"
              style="width: 100%"
            >
              <el-option
                v-for="dict in dict.type.bc_political_type"
                :key="dict.value"
                :label="dict.label"
                :value="dict.value"
              ></el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="曾用名" prop="formerName">
            <el-input
              v-model.trim="form.formerName"
              clearable
              placeholder="请输入曾用名"
              maxlength="10"
            />
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="籍贯" prop="bnpId">
            <el-cascader
              v-model="form.bnpId"
              clearable
              style="width: 100%"
              :props="{ value: 'unitCode', currentLabels: 'label' }"
              :options="options"
              @change="handlePlace"
            ></el-cascader>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="职称" prop="title">
            <el-select
              v-model="form.title"
              clearable
              placeholder="请选择职称"
              style="width: 100%"
            >
              <el-option
                v-for="dict in dict.type.basic_title_type"
                :key="dict.value"
                :label="dict.label"
                :value="dict.value"
              ></el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="职称级别" prop="titleLevel">
            <el-select
              v-model="form.titleLevel"
              clearable
              placeholder="请选择职称级别"
              style="width: 100%"
            >
              <el-option
                v-for="dict in dict.type.basic_title_level"
                :key="dict.value"
                :label="dict.label"
                :value="dict.value"
              ></el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item
            label="角色"
            prop="roles"
            v-if="this.cId ? false : true"
          >
            <el-select
              v-model="form.roles"
              clearable
              placeholder="请选择角色"
              style="width: 100%"
            >
              <el-option
                v-for="item in roleOptions"
                :key="item.roleId"
                :label="item.roleName"
                :value="item"
                :disabled="item.status == 1"
              ></el-option>
            </el-select>
          </el-form-item>
          
        </el-col>
      </el-row>
      <h2>所带班级</h2>
      <el-table :data="sendUserIds" ref="clrWorkHistory">
        <el-table-column label="序号" align="center" type="index" width="50" />
        <el-table-column
          label="所属院系"
          prop="deptNames"
          :show-overflow-tooltip="true"
          align="center"
        ></el-table-column>
        <el-table-column
          label="专业"
          prop="specialtyName"
          align="center"
        ></el-table-column>
        <el-table-column
          label="入学年级"
          prop="gradeName"
          align="center"
        ></el-table-column>
        <el-table-column
          label="班号"
          prop="classCode"
          align="center"
        ></el-table-column>
        <el-table-column
          label="班级名称"
          prop="className"
          :show-overflow-tooltip="true"
          align="center"
        ></el-table-column>
        <el-table-column
          label="班级人数"
          prop="classSize"
          align="center"
        ></el-table-column>
      </el-table>
    </el-form>
    <!-- <fromIndex :distributionRow="distributionRow"></fromIndex> -->
    <div slot="footer" class="dialog-footer">
      <el-button type="primary" @click="submitForm">确定</el-button>
      <el-button @click="openDlg = false">取消</el-button>
    </div>
  </el-dialog>
</template>
<script>
import { listRole } from "@/api/system/role";
import { getUser, deptTreeSelect } from "@/api/system/user";
import { counsellorInforTid } from "@/api/counselor/index";
import Validators from "@/utils/validate.js";
import { getProvinceTree } from "@/api/information/classInfor";
import { classTree } from "@/api/information/studentInfor";
export default {
  name: "Apprclrinfo",
  components: {},

  dicts: [
    "clr_appr_status",
    "basic_education_type", // 学历类型
    "basic_degree_type", // 学位类型
    "sys_user_sex", // 性别
    "bc_political_type", // 政治面貌
    "bc_nation_type", // 民族类型
    "clr_counsellor_type", // 是否辅导员
    "clr_cthr_type", // 是否班主任
    "bc_office_type", // 任职类型
    "basic_post_status", //在岗状态
    "clr_learning_style", //学习方式
    "clr_learning_forms", //学习形式
    "clr_school_type", //学校类型
    "sys_yes_no", //学位类型
    "basic_blood_type", // 血型
    "basic_title_type", // 职称类型
    "basic_title_level", // 职称级别
    "clr_country_type", // 授予国家
    "bc_speciality_type", //学制类型
  ],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 子表选中数据
      checkedClrApprRecord: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      openDlg: false,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 辅导员信息申请单表格数据
      apprclrinfoList: [],
      // 辅导员审批记录表格数据
      clrApprRecordList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      deptOptions: [],
      options: [], // 籍贯
      clrEducationList: [], //
      formWork: {},
      clrWorkHistoryList: [],
      educationSname: [],
      dataTime: [],
      workDisabled: false,
      educationDisabled: false,
      multipleEducation: true,
      sendUserIds: [],
      roleOptions: [],

      // 表单参数
      form: {
        teacher: {},
        deptId: "",
      },
      cId: "", //教师ID
      tId: "",
      type: null, // 调整类型（A:新增信息,E:修改信息）
      educationFrom: {},
      // 表单校验
      rules: {
        // deptId: [
        //   { required: true, message: "请选择所属院系", trigger: "change" }
        // ],
        admissionTime: [
          { required: true, message: "请选择来校时间", trigger: "change" },
        ],
        postStatus: [
          { required: true, message: "请选择岗位状态", trigger: "change" },
        ],
        tno: [
          {
            required: true,
            text: "请输入工号",
            validator: Validators.istext,
            trigger: "blur",
          },
        ],
        name: [
          {
            required: true,
            text: "请输入姓名",
            validator: Validators.isString,
            trigger: "blur",
          },
        ],
        sex: [{ required: true, message: "请选择性别", trigger: "change" }],
        bloodType: [
          { required: false, message: "请选择血型", trigger: "change" },
        ],
        cardCode: [
          { required: false, message: "请输入身份证号", trigger: "blur" },
          {
            message: "请输入正确的身份证号",
            pattern:
              /^[1-9]\d{5}(18|19|([23]\d))\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx]+$/,
            trigger: "blur",
          },
        ],
        phone: [
          { required: false, message: "请输入联系方式", trigger: "blur" },
          {
            message: "请输入正确的身份证号",
            pattern: /^1\d{10}$/,
            trigger: "blur",
          },
        ],
        birthday: [
          { required: false, message: "请选择出生日期", trigger: "change" },
        ],
        nation: [{ required: false, message: "请选择民族", trigger: "change" }],
        political: [
          { required: false, message: "请选择政治面貌", trigger: "change" },
        ],
        formerName: [
          {
            required: false,
            text: "请输入曾用名",
            // validator: Validators.isString,
            trigger: "blur",
          },
        ],
        bnpId: [
          { required: false, message: "请选择籍贯", trigger: "change" },
        ],
        education: [
          { required: false, message: "请选择学历", trigger: "change" },
        ],
        acDegree: [
          { required: false, message: "请选择学位", trigger: "change" },
        ],
        braidType: [
          { required: false, message: "请选择编制类型", trigger: "change" },
        ],
        title: [{ required: false, message: "请选择职称", trigger: "change" }],
        titleLevel: [
          { required: false, message: "请选择职称级别", trigger: "change" },
        ],
        nature: [
          { required: false, message: "请选择教师性质", trigger: "change" },
        ],
        roles: [{ required: true, message: "请选择角色", trigger: "change" }],
      },
    };
  },
  mounted() {
    this.department();
   
    // 籍贯下拉书
    getProvinceTree().then((response) => {
      this.options = response.data;
    });
  },
  computed: {
    userInfor() {
      return this.$store.state.user.userInfor;
    },
  },
  methods: {
    openIndex(row) {
      console.log(row, "....");
      this.form = row.teacher;
      if (this.form.id) {
        // 查询辅导员信息列表
        counsellorInforTid(this.form.id).then((res) => {
          if (res.data) {
            this.cId = res.data.cId;
            this.tId = res.data.tId;
            this.sendUserIds = res.data.classList;
            console.log(res, "lllll");
            this.form = res.data.teacher;
          }else{
            getUser().then((response) => {
      this.roleOptions = response.roles.filter((item) => {
        return item.roleName == "辅导员";
      });
    });
          }
          console.log(this.cId, "dsadhskaj");
        });
      }
      this.openDlg = true;
    },
    handleChange(value) {
      this.form.deptId = value[value.length - 1];
      // this.form.deptId = value[2];
      // this.form.multistage = value + "";
    },
    handlePlace(data) {
      this.form.bnpId = data[data.length - 1];
    },

    // 清空所带班级
    handleDelete() {
      this.sendUserIds = [];
    },
    // 取消按钮
    cancel() {
      this.open = false;
    },
    // 清除表单
    CloseIn() {
      this.form = {};
      this.formTeacher = {};
      this.open = false;
    },
    // 根据身份证号获取出生年月
    codeBulr() {
      if (this.form.cardCode) {
        this.$set(this.form, "birthday", this.getBirthday(this.form.cardCode));
      }
    },

    // 弹窗取消
    educationalCancel() {
      this.educationalVisible = false;
      this.resetForm("educationFrom");
    },
    // 获取部门信息
    async department() {
      await deptTreeSelect().then((res) => {
        this.deptOptions = res.data;
      });
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate((valid) => {
        if (valid) {
         
            let data = {
              ...this.form,
              cId: this.cId,
              tId: this.tId,
              classList: this.sendUserIds,
            };
            this.$emit("getAdjust", data);
            this.openDlg = false;
        }
      });
    },
  },
};
</script>
      